package com.peng.controller;

import com.peng.service.ChatAssistant;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatLanguageModelController {
    @Resource
    private ChatLanguageModel chatLanguageModel;
    @Resource
    private ChatAssistant chatAssistant;

    // http://localhost:9002/chatapi/hello
    @GetMapping(value = "/chatapi/hello")
    public String hello(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt) {
        String result = chatLanguageModel.generate(prompt);
        System.out.println("通过langchain4j调用qwen-turbo模型返回结果："+result);
        return result;
    }

    //http://localhost:9002/chatapi/lowapi?prompt=茅台怎么样
    @GetMapping(value = "/chatapi/lowapi")
    public String lowApi(@RequestParam("prompt") String prompt) {

        Response<AiMessage> aiMessageResponse = chatLanguageModel.generate(UserMessage.from(prompt));

        return aiMessageResponse.content().text();
    }

    @GetMapping(value = "/chatapi/hightapi")
    public String hightApi(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt) {
        return chatAssistant.chat(prompt);
    }
}